import router from '@/router';
import { ElNotification } from 'element-plus';
import { start, done } from 'nprogress'
import { store } from '@/store';
import 'nprogress/nprogress.css'

router.beforeEach(async (to, from, next): Promise<void> => {
    start();

    console.log(store.state.user);
    
    // 判断是否获取用户信息
    const userInfo = store.state.user.userInfo;
    if (store.getters.hasLogin && !Boolean(userInfo)) {
        // 不存在用户信息 调用api获取用户信息
        try {
            await store.dispatch('user/getUserInfo');
        } catch (error) {

        }
    }

    next();
})

router.afterEach((): void => {
    done();
})